package com.sky.controller.user;

import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userOrdersController")
@RequestMapping("/user/order")
@Api(tags = "订单接口")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @PostMapping("/submit")
    @ApiOperation("用户下单")
    public Result saveOrders(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        return ordersService.saveOrders(ordersSubmitDTO);
    }

    //支付
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO){
        return ordersService.payment(ordersPaymentDTO);
    }

    @GetMapping("/historyOrders")
    @ApiOperation("查询历史订单")
    public Result ordersList(String page,String pageSize, String status){

        return ordersService.ordersList(page,pageSize,status);
    }

    @GetMapping("/orderDetail/{id}")
    @ApiOperation("查询订单详情")
    public Result getOrdersDetailById(@PathVariable String id){
        return ordersService.getOrdersDetailById(id);
    }

    @PutMapping("/cancel/{id}")
    @ApiOperation("取消订单")
    public Result cancel(@PathVariable String id){
        return ordersService.cancel(id);
//        return Result.success();
    }


    @PostMapping("repetition/{id}")
    @ApiOperation("再来一单")
    public Result repetition(@PathVariable String id){
        return ordersService.repetition(id);
    }

}
